// 该文件用来管理侧边栏的收缩与展开状态的仓库--bool（暂时不重要，可忽略）
import Cookies from 'js-cookie'
import { defineStore } from 'pinia'

export const useAppStore = defineStore({
  id: 'app',
  state: () => ({
    sidebar: {
      //opened为侧边栏的打开状态
      opened: Cookies.get('sidebarStatus') ? !!+(Cookies.get('sidebarStatus') as string) : true,
      withoutAnimation: false
    },
    device: 'desktop'
  }),
  
  actions: {
    // 点击打开或侧边栏按钮触发的函数，将opened取反
    toggleSidebar () {
      console.log(this.sidebar.opened,55)
      this.sidebar.opened = !this.sidebar.opened
      this.sidebar.withoutAnimation = false
      if (this.sidebar.opened) {
        Cookies.set('sidebarStatus', '1')
      } else {
        Cookies.set('sidebarStatus', '0')
      }
    },
    //非全屏状态下窗口缩放触发函数
    closeSidebar(withoutAnimation: boolean) {
      Cookies.set('sidebarStatus', '0')
      this.sidebar.opened = false
      this.sidebar.withoutAnimation = withoutAnimation
    },
    //全屏与非全屏状态下窗口缩放触发
    toggleDevice(device: string) {
      this.device = device
    }
  }
})